<?php

add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );

class stSocialMediaToolboxFunctions extends stfunctions_2_1 {

    public function __construct($config) {
        parent::__construct($config);
        $this->config ['appDir'] = $this->config['pluginDir'] . 'applications/';        
    }
    public function image_zoom($file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90, $x2= 55, $y2 = 76) {
        $image = wp_load_image($file);
        if (!is_resource($image))
            return new WP_Error('error_loading_image', $image, $file);

        $size = @getimagesize($file);
        if (!$size)
            return new WP_Error('invalid_image', __('Could not read image size'), $file);
        list($orig_w, $orig_h, $orig_type) = $size;
        if ($crop) {
            $dims = array(0, 0, $x2, $y2, $max_w, $max_h, 436, 292);
        } else {
            $dims = array(0, 0, 0, 0, $max_w, $max_h, $orig_w, $orig_h);
        }

        list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;

        $newimage = wp_imagecreatetruecolor($dst_w, $dst_h);
        imagecopyresampled($newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
        // convert from full colors to index colors, like original PNG.
        if (IMAGETYPE_PNG == $orig_type && function_exists('imageistruecolor') && !imageistruecolor($image))
            imagetruecolortopalette($newimage, false, imagecolorstotal($image));

        // we don't need the original in memory anymore
        imagedestroy($image);

        // $suffix will be appended to the destination filename, just before the extension
        if (!$suffix)
            $suffix = "{$dst_w}x{$dst_h}";

        $info = pathinfo($file);
        $dir = $info['dirname'];
        $ext = $info['extension'];
        $name = wp_basename($file, ".$ext");

        if (!is_null($dest_path) and $_dest_path = realpath($dest_path))
            $dir = $_dest_path;
        $destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";

        if (IMAGETYPE_GIF == $orig_type) {
            if (!imagegif($newimage, $destfilename))
                return new WP_Error('resize_path_invalid', __('Resize path invalid'));
        } elseif (IMAGETYPE_PNG == $orig_type) {
            if (!imagepng($newimage, $destfilename))
                return new WP_Error('resize_path_invalid', __('Resize path invalid'));
        } else {
            // all other formats are converted to jpg
            $destfilename = "{$dir}/{$name}-{$suffix}.jpg";
            if (!imagejpeg($newimage, $destfilename, apply_filters('jpeg_quality', $jpeg_quality, 'image_resize')))
                return new WP_Error('resize_path_invalid', __('Resize path invalid'));
        }

        imagedestroy($newimage);

        // Set correct file permissions
        $stat = stat(dirname($destfilename));
        $perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits
        @ chmod($destfilename, $perms);

        return $destfilename;
    }
}

?>